<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>axios其他使用</title>
	<link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" crossorigin="anonymous">
	<script src="https://cdn.bootcdn.net/ajax/libs/axios/1.7.8/axios.min.js"></script>
</head>
<body>
	<div class="container">
		<h2 class="page-header">默认配置</h2>
		<button class="btn btn-primary"> 发送GET请求 </button>
		<button class="btn btn-warning"> 发送POST请求 </button>
		<button class="btn btn-success"> 发送PUT请求 </button>
		<button class="btn btn-danger"> 发送DELETE请求 </button>
	</div>
	<script>
		// 获取按钮
		const btns = document.querySelectorAll('button');
		// 默认配置
		axios.defaults.method = 'GET' //设置默认的请求类型为 GET
		axios.defaults.baseURL = 'http://localhost:3000'; // 设置基础 URL
		axios.defaults.params = {id:100}
		axios.defaults.timeout = 3000;

		// 发送GET请求
		btns[0].onclick = function() {
			axios.request({
				url:'/posts'
			}).then(res=>{
				console.log(res);
			})
		}
	</script>
</body>
</html>